#include <gtest/gtest.h>

#ifndef private
#define private public
#include "acl/acl.h"
#include "acl/acl_op_compiler.h"
#include "acl/acl_prof.h"
#include "acl/acl_tdt.h"
#include "acl/error_codes/ge_error_codes.h"
#include "acl/error_codes/rt_error_codes.h"
#include "log_inner.h"
#include "utils/cann_info_utils.h"
#undef private
#endif

class UTEST_ACL_compatibility_const_check : public testing::Test
{
    public:
        UTEST_ACL_compatibility_const_check() {}
    protected:
        virtual void SetUp() {}
        virtual void TearDown() {}
};

TEST_F(UTEST_ACL_compatibility_const_check, ge_error_codes)
{
    EXPECT_EQ(ACL_ERROR_GE_PARAM_INVALID, 145000);
    EXPECT_EQ(ACL_ERROR_GE_EXEC_NOT_INIT, 145001);
    EXPECT_EQ(ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID, 145002);
    EXPECT_EQ(ACL_ERROR_GE_EXEC_MODEL_ID_INVALID, 145003);
    EXPECT_EQ(ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID, 145006);
    EXPECT_EQ(ACL_ERROR_GE_EXEC_MODEL_ADDR_INVALID, 145007);
    EXPECT_EQ(ACL_ERROR_GE_EXEC_MODEL_QUEUE_ID_INVALID, 145008);
    EXPECT_EQ(ACL_ERROR_GE_EXEC_LOAD_MODEL_REPEATED, 145009);
    EXPECT_EQ(ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID, 145011);
    EXPECT_EQ(ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID, 145012);
    EXPECT_EQ(ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID, 145013);
    EXPECT_EQ(ACL_ERROR_GE_AIPP_BATCH_EMPTY, 145014);
    EXPECT_EQ(ACL_ERROR_GE_AIPP_NOT_EXIST, 145015);
    EXPECT_EQ(ACL_ERROR_GE_OP_TASK_TYPE_INVALID, 145017);
    EXPECT_EQ(ACL_ERROR_GE_OP_KERNEL_TYPE_INVALID, 145018);
    EXPECT_EQ(ACL_ERROR_GE_PLGMGR_PATH_INVALID, 145019);
    EXPECT_EQ(ACL_ERROR_GE_FORMAT_INVALID, 145020);
    EXPECT_EQ(ACL_ERROR_GE_SHAPE_INVALID, 145021);
    EXPECT_EQ(ACL_ERROR_GE_DATATYPE_INVALID, 145022);
    EXPECT_EQ(ACL_ERROR_GE_MEMORY_ALLOCATION, 245000);
    EXPECT_EQ(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, 245001);
    EXPECT_EQ(ACL_ERROR_GE_EXEC_LOAD_MODEL_PARTITION_FAILED, 545002);
    EXPECT_EQ(ACL_ERROR_GE_EXEC_LOAD_WEIGHT_PARTITION_FAILED, 545003);
    EXPECT_EQ(ACL_ERROR_GE_EXEC_LOAD_TASK_PARTITION_FAILED, 545004);
    EXPECT_EQ(ACL_ERROR_GE_EXEC_LOAD_KERNEL_PARTITION_FAILED, 545005);
    EXPECT_EQ(ACL_ERROR_GE_EXEC_RELEASE_MODEL_DATA, 545006);
    EXPECT_EQ(ACL_ERROR_GE_COMMAND_HANDLE, 545007);
    EXPECT_EQ(ACL_ERROR_GE_GET_TENSOR_INFO, 545008);
    EXPECT_EQ(ACL_ERROR_GE_UNLOAD_MODEL, 545009);
}

TEST_F(UTEST_ACL_compatibility_const_check, rt_error_codes)
{
    EXPECT_EQ(ACL_ERROR_RT_PARAM_INVALID, 107000);
    EXPECT_EQ(ACL_ERROR_RT_INVALID_DEVICEID, 107001);
    EXPECT_EQ(ACL_ERROR_RT_CONTEXT_NULL, 107002);
    EXPECT_EQ(ACL_ERROR_RT_STREAM_CONTEXT, 107003);
    EXPECT_EQ(ACL_ERROR_RT_MODEL_CONTEXT, 107004);
    EXPECT_EQ(ACL_ERROR_RT_STREAM_MODEL, 107005);
    EXPECT_EQ(ACL_ERROR_RT_EVENT_TIMESTAMP_INVALID, 107006);
    EXPECT_EQ(ACL_ERROR_RT_EVENT_TIMESTAMP_REVERSAL, 107007);
    EXPECT_EQ(ACL_ERROR_RT_ADDR_UNALIGNED, 107008);
    EXPECT_EQ(ACL_ERROR_RT_FILE_OPEN, 107009);
    EXPECT_EQ(ACL_ERROR_RT_FILE_WRITE, 107010);
    EXPECT_EQ(ACL_ERROR_RT_STREAM_SUBSCRIBE, 107011);
    EXPECT_EQ(ACL_ERROR_RT_THREAD_SUBSCRIBE, 107012);
    EXPECT_EQ(ACL_ERROR_RT_GROUP_NOT_SET, 107013);
    EXPECT_EQ(ACL_ERROR_RT_GROUP_NOT_CREATE, 107014);
    EXPECT_EQ(ACL_ERROR_RT_STREAM_NO_CB_REG, 107015);
    EXPECT_EQ(ACL_ERROR_RT_INVALID_MEMORY_TYPE, 107016);
    EXPECT_EQ(ACL_ERROR_RT_INVALID_HANDLE, 107017);
    EXPECT_EQ(ACL_ERROR_RT_INVALID_MALLOC_TYPE, 107018);

    EXPECT_EQ(ACL_ERROR_RT_FEATURE_NOT_SUPPORT, 207000);
    EXPECT_EQ(ACL_ERROR_RT_MEMORY_ALLOCATION, 207001);
    EXPECT_EQ(ACL_ERROR_RT_MEMORY_FREE, 207002);
    EXPECT_EQ(ACL_ERROR_RT_AICORE_OVER_FLOW, 207003);
    EXPECT_EQ(ACL_ERROR_RT_NO_DEVICE, 207004);
    EXPECT_EQ(ACL_ERROR_RT_RESOURCE_ALLOC_FAIL, 207005);
    EXPECT_EQ(ACL_ERROR_RT_NO_PERMISSION, 207006);
    EXPECT_EQ(ACL_ERROR_RT_NO_EVENT_RESOURCE, 207007);
    EXPECT_EQ(ACL_ERROR_RT_NO_STREAM_RESOURCE, 207008);
    EXPECT_EQ(ACL_ERROR_RT_NO_NOTIFY_RESOURCE, 207009);
    EXPECT_EQ(ACL_ERROR_RT_NO_MODEL_RESOURCE, 207010);

    EXPECT_EQ(ACL_ERROR_RT_INTERNAL_ERROR, 507000);
    EXPECT_EQ(ACL_ERROR_RT_TS_ERROR, 507001);
    EXPECT_EQ(ACL_ERROR_RT_STREAM_TASK_FULL, 507002);
    EXPECT_EQ(ACL_ERROR_RT_STREAM_TASK_EMPTY, 507003);
    EXPECT_EQ(ACL_ERROR_RT_STREAM_NOT_COMPLETE, 507004);
    EXPECT_EQ(ACL_ERROR_RT_END_OF_SEQUENCE, 507005);
    EXPECT_EQ(ACL_ERROR_RT_EVENT_NOT_COMPLETE, 507006);
    EXPECT_EQ(ACL_ERROR_RT_CONTEXT_RELEASE_ERROR, 507007);
    EXPECT_EQ(ACL_ERROR_RT_SOC_VERSION, 507008);
    EXPECT_EQ(ACL_ERROR_RT_TASK_TYPE_NOT_SUPPORT, 507009);
    EXPECT_EQ(ACL_ERROR_RT_LOST_HEARTBEAT, 507010);
    EXPECT_EQ(ACL_ERROR_RT_MODEL_EXECUTE, 507011);
    EXPECT_EQ(ACL_ERROR_RT_REPORT_TIMEOUT, 507012);
    EXPECT_EQ(ACL_ERROR_RT_SYS_DMA, 507013);
    EXPECT_EQ(ACL_ERROR_RT_AICORE_TIMEOUT, 507014);
    EXPECT_EQ(ACL_ERROR_RT_AICORE_EXCEPTION, 507015);
    EXPECT_EQ(ACL_ERROR_RT_AICORE_TRAP_EXCEPTION, 507016);
    EXPECT_EQ(ACL_ERROR_RT_AICPU_TIMEOUT, 507017);
    EXPECT_EQ(ACL_ERROR_RT_AICPU_EXCEPTION, 507018);
    EXPECT_EQ(ACL_ERROR_RT_AICPU_DATADUMP_RSP_ERR, 507019);
    EXPECT_EQ(ACL_ERROR_RT_AICPU_MODEL_RSP_ERR, 507020);
    EXPECT_EQ(ACL_ERROR_RT_PROFILING_ERROR, 507021);
    EXPECT_EQ(ACL_ERROR_RT_IPC_ERROR, 507022);
    EXPECT_EQ(ACL_ERROR_RT_MODEL_ABORT_NORMAL, 507023);
    EXPECT_EQ(ACL_ERROR_RT_KERNEL_UNREGISTERING, 507024);
    EXPECT_EQ(ACL_ERROR_RT_RINGBUFFER_NOT_INIT, 507025);
    EXPECT_EQ(ACL_ERROR_RT_RINGBUFFER_NO_DATA, 507026);
    EXPECT_EQ(ACL_ERROR_RT_KERNEL_LOOKUP, 507027);
    EXPECT_EQ(ACL_ERROR_RT_KERNEL_DUPLICATE, 507028);
    EXPECT_EQ(ACL_ERROR_RT_DEBUG_REGISTER_FAIL, 507029);
    EXPECT_EQ(ACL_ERROR_RT_DEBUG_UNREGISTER_FAIL, 507030);
    EXPECT_EQ(ACL_ERROR_RT_LABEL_CONTEXT, 507031);
    EXPECT_EQ(ACL_ERROR_RT_PROGRAM_USE_OUT, 507032);
    EXPECT_EQ(ACL_ERROR_RT_DEV_SETUP_ERROR, 507033);
    EXPECT_EQ(ACL_ERROR_RT_VECTOR_CORE_TIMEOUT, 507034);
    EXPECT_EQ(ACL_ERROR_RT_VECTOR_CORE_EXCEPTION, 507035);
    EXPECT_EQ(ACL_ERROR_RT_VECTOR_CORE_TRAP_EXCEPTION, 507036);

    EXPECT_EQ(ACL_ERROR_RT_DRV_INTERNAL_ERROR, 507899);
    EXPECT_EQ(ACL_ERROR_RT_AICPU_INTERNAL_ERROR, 507900);
    EXPECT_EQ(ACL_ERROR_RT_SOCKET_CLOSE, 507901);
}

TEST_F(UTEST_ACL_compatibility_const_check, acl)
{
    EXPECT_EQ(ACL_MAJOR_VERSION, 1);
    EXPECT_EQ(ACL_MINOR_VERSION, 9);
    EXPECT_EQ(ACL_PATCH_VERSION, 0);
}

TEST_F(UTEST_ACL_compatibility_const_check, acl_mdl)
{
    EXPECT_EQ(ACL_MAX_DIM_CNT, 128);
    EXPECT_EQ(ACL_MAX_TENSOR_NAME_LEN, 128);
    EXPECT_EQ(ACL_MAX_BATCH_NUM, 128);
    EXPECT_EQ(ACL_MAX_HW_NUM, 128);
    EXPECT_EQ(ACL_MAX_SHAPE_COUNT, 128);
    EXPECT_EQ(ACL_INVALID_NODE_INDEX,  0xFFFFFFFF);

    EXPECT_EQ(ACL_MDL_LOAD_FROM_FILE, 1);
    EXPECT_EQ(ACL_MDL_LOAD_FROM_FILE_WITH_MEM, 2);
    EXPECT_EQ(ACL_MDL_LOAD_FROM_MEM, 3);
    EXPECT_EQ(ACL_MDL_LOAD_FROM_MEM_WITH_MEM, 4);
    EXPECT_EQ(ACL_MDL_LOAD_FROM_FILE_WITH_Q, 5);
    EXPECT_EQ(ACL_MDL_LOAD_FROM_MEM_WITH_Q, 6);

    EXPECT_EQ(std::string(ACL_DYNAMIC_TENSOR_NAME), std::string("ascend_mbatch_shape_data"));
    EXPECT_EQ(std::string(ACL_DYNAMIC_AIPP_NAME), std::string("ascend_dynamic_aipp_data"));
    EXPECT_EQ(std::string(ACL_ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES), std::string("_datadump_original_op_names"));
}

TEST_F(UTEST_ACL_compatibility_const_check, acl_base)
{
    EXPECT_EQ(ACL_ERROR_NONE, 0);
    EXPECT_EQ(ACL_SUCCESS, 0);

    EXPECT_EQ(ACL_ERROR_INVALID_PARAM, 100000);
    EXPECT_EQ(ACL_ERROR_UNINITIALIZE, 100001);
    EXPECT_EQ(ACL_ERROR_REPEAT_INITIALIZE, 100002);
    EXPECT_EQ(ACL_ERROR_INVALID_FILE, 100003);
    EXPECT_EQ(ACL_ERROR_WRITE_FILE, 100004);
    EXPECT_EQ(ACL_ERROR_INVALID_FILE_SIZE, 100005);
    EXPECT_EQ(ACL_ERROR_PARSE_FILE, 100006);
    EXPECT_EQ(ACL_ERROR_FILE_MISSING_ATTR, 100007);
    EXPECT_EQ(ACL_ERROR_FILE_ATTR_INVALID, 100008);
    EXPECT_EQ(ACL_ERROR_INVALID_DUMP_CONFIG, 100009);
    EXPECT_EQ(ACL_ERROR_INVALID_PROFILING_CONFIG, 100010);
    EXPECT_EQ(ACL_ERROR_INVALID_MODEL_ID, 100011);
    EXPECT_EQ(ACL_ERROR_DESERIALIZE_MODEL, 100012);
    EXPECT_EQ(ACL_ERROR_PARSE_MODEL, 100013);
    EXPECT_EQ(ACL_ERROR_READ_MODEL_FAILURE, 100014);
    EXPECT_EQ(ACL_ERROR_MODEL_SIZE_INVALID, 100015);
    EXPECT_EQ(ACL_ERROR_MODEL_MISSING_ATTR, 100016);
    EXPECT_EQ(ACL_ERROR_MODEL_INPUT_NOT_MATCH, 100017);
    EXPECT_EQ(ACL_ERROR_MODEL_OUTPUT_NOT_MATCH, 100018);
    EXPECT_EQ(ACL_ERROR_MODEL_NOT_DYNAMIC, 100019);
    EXPECT_EQ(ACL_ERROR_OP_TYPE_NOT_MATCH, 100020);
    EXPECT_EQ(ACL_ERROR_OP_INPUT_NOT_MATCH, 100021);
    EXPECT_EQ(ACL_ERROR_OP_OUTPUT_NOT_MATCH, 100022);
    EXPECT_EQ(ACL_ERROR_OP_ATTR_NOT_MATCH, 100023);
    EXPECT_EQ(ACL_ERROR_OP_NOT_FOUND, 100024);
    EXPECT_EQ(ACL_ERROR_OP_LOAD_FAILED, 100025);
    EXPECT_EQ(ACL_ERROR_UNSUPPORTED_DATA_TYPE, 100026);
    EXPECT_EQ(ACL_ERROR_FORMAT_NOT_MATCH, 100027);
    EXPECT_EQ(ACL_ERROR_BIN_SELECTOR_NOT_REGISTERED, 100028);
    EXPECT_EQ(ACL_ERROR_KERNEL_NOT_FOUND, 100029);
    EXPECT_EQ(ACL_ERROR_BIN_SELECTOR_ALREADY_REGISTERED, 100030);
    EXPECT_EQ(ACL_ERROR_KERNEL_ALREADY_REGISTERED, 100031);
    EXPECT_EQ(ACL_ERROR_INVALID_QUEUE_ID, 100032);
    EXPECT_EQ(ACL_ERROR_REPEAT_SUBSCRIBE, 100033);
    EXPECT_EQ(ACL_ERROR_STREAM_NOT_SUBSCRIBE, 100034);
    EXPECT_EQ(ACL_ERROR_THREAD_NOT_SUBSCRIBE, 100035);
    EXPECT_EQ(ACL_ERROR_WAIT_CALLBACK_TIMEOUT, 100036);
    EXPECT_EQ(ACL_ERROR_REPEAT_FINALIZE, 100037);
    EXPECT_EQ(ACL_ERROR_NOT_STATIC_AIPP, 100038);
    EXPECT_EQ(ACL_ERROR_COMPILING_STUB_MODE, 100039);
    EXPECT_EQ(ACL_ERROR_GROUP_NOT_SET, 100040);
    EXPECT_EQ(ACL_ERROR_GROUP_NOT_CREATE, 100041);
    EXPECT_EQ(ACL_ERROR_PROF_ALREADY_RUN, 100042);
    EXPECT_EQ(ACL_ERROR_PROF_NOT_RUN, 100043);
    EXPECT_EQ(ACL_ERROR_DUMP_ALREADY_RUN, 100044);
    EXPECT_EQ(ACL_ERROR_DUMP_NOT_RUN, 100045);
    EXPECT_EQ(ACL_ERROR_PROF_REPEAT_SUBSCRIBE, 148046);
    EXPECT_EQ(ACL_ERROR_PROF_API_CONFLICT, 148047);
    EXPECT_EQ(ACL_ERROR_INVALID_MAX_OPQUEUE_NUM_CONFIG, 148048);
    EXPECT_EQ(ACL_ERROR_INVALID_OPP_PATH, 148049);
    EXPECT_EQ(ACL_ERROR_OP_UNSUPPORTED_DYNAMIC, 148050);
    EXPECT_EQ(ACL_ERROR_RELATIVE_RESOURCE_NOT_CLEARED, 148051);

    EXPECT_EQ(ACL_ERROR_BAD_ALLOC, 200000);
    EXPECT_EQ(ACL_ERROR_API_NOT_SUPPORT, 200001);
    EXPECT_EQ(ACL_ERROR_INVALID_DEVICE, 200002);
    EXPECT_EQ(ACL_ERROR_MEMORY_ADDRESS_UNALIGNED, 200003);
    EXPECT_EQ(ACL_ERROR_RESOURCE_NOT_MATCH, 200004);
    EXPECT_EQ(ACL_ERROR_INVALID_RESOURCE_HANDLE, 200005);
    EXPECT_EQ(ACL_ERROR_FEATURE_UNSUPPORTED, 200006);
    EXPECT_EQ(ACL_ERROR_PROF_MODULES_UNSUPPORTED, 200007);

    EXPECT_EQ(ACL_ERROR_STORAGE_OVER_LIMIT, 300000);

    EXPECT_EQ(ACL_ERROR_INTERNAL_ERROR, 500000);
    EXPECT_EQ(ACL_ERROR_FAILURE, 500001);
    EXPECT_EQ(ACL_ERROR_GE_FAILURE, 500002);
    EXPECT_EQ(ACL_ERROR_RT_FAILURE, 500003);
    EXPECT_EQ(ACL_ERROR_DRV_FAILURE, 500004);
    EXPECT_EQ(ACL_ERROR_PROFILING_FAILURE, 500005);

    EXPECT_EQ(ACL_TENSOR_SHAPE_RANGE_NUM, 2);
    EXPECT_EQ(ACL_TENSOR_VALUE_RANGE_NUM, 2);
    EXPECT_EQ(ACL_UNKNOWN_RANK, 0xFFFFFFFFFFFFFFFE);
}

TEST_F(UTEST_ACL_compatibility_const_check, acl_prof)
{
    EXPECT_EQ(ACL_PROF_ACL_API, 0x0001);
    EXPECT_EQ(ACL_PROF_TASK_TIME, 0x0002);
    EXPECT_EQ(ACL_PROF_AICORE_METRICS, 0x0004);
    EXPECT_EQ(ACL_PROF_AICPU, 0x0008);

    EXPECT_EQ(ACL_PROF_MAX_OP_NAME_LEN, 257);
    EXPECT_EQ(ACL_PROF_MAX_OP_TYPE_LEN, 65);
}

TEST_F(UTEST_ACL_compatibility_const_check, acl_op)
{
    EXPECT_EQ(ACL_COMPILE_FLAG_BIN_SELECTOR, 1);
}

TEST_F(UTEST_ACL_compatibility_const_check, acl_capability) {
    //
    EXPECT_LE(acl::CannInfoUtils::attrToCannInfo_.size(), acl::MAX_CANN_ATTR_SIZE);
}